#if !USE_CONSOLE
#include "src/interface/imageDialog.h"

#include <QRgb>

ImageDialog::ImageDialog(QWidget *_parent, Scene *_scene) : QDialog(_parent){
    setWindowTitle(QString::fromUtf8("Raytracing"));
    image = new Image(this, _scene);

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(image);

    setLayout(mainLayout);
}

ImageDialog::~ImageDialog(){
    delete image;
}

void ImageDialog::setImageSize(unsigned int _m, unsigned int _n){
    QImage *img = new QImage(_m, _n, QImage::Format_RGB32);
    resize(_m + 100, _n + 150);
//    std::cout <<"Criando uma imagem de " << _m << " por " << _n
//              <<" .\nE ela tem: " <<img->width() << " por "<<img->height()<<std::endl;
//
    img->fill(0);


    image->update(img);
}

void ImageDialog::updateImageLine(unsigned int _i, uchar *_line){
    QImage *img = image->getImage();
//    QRgb* current = (QRgb*)img->scanLine(_i);


    for(int i = 0; i < img->width(); i++){
        QRgb value = qRgb(_line[3*i], _line[(3*i)+1], _line[(3*i)+2]);
        img->setPixel(i, _i, value);
    }

    image->update();
}

#endif //!USE_CONSOLE
